#include "selectwindow.h"

SelectWindow::SelectWindow(QWidget *parent) : QMainWindow(parent)
{
    //设置固定尺寸
    this->setFixedSize(1000,800);

    //设置标题
    this->setWindowTitle("df推箱子");

    //设置图标
    this->setWindowIcon(QIcon(":/res/df.jpg"));

    //创建返回按钮
    GPushButton *backBtn = new GPushButton(":/res/BACK.png",":/res/backBtn.png");
    backBtn->setParent(this);
    backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());
    connect(backBtn,&GPushButton::clicked,[=]{
        //qDebug()<<"返回到主场景";

        //延时发送信号
        QTimer::singleShot(200,this,[=]{
        //发送点击返回按钮的信号
            emit this->ChooseSceneBack();
        });
    });

    // 置空关卡
    this->pScene = NULL;
    double position[4][2]={
        123.2,311.9,
        368.5,247.0,
        474.2,517.6,
        657.0,455.7
    };

    //创建选关按钮
    for(int i=0;i<4;i++)
    {
        GPushButton *levelBtn = new GPushButton(QString(":/res/gq%1.jpg").arg(i+1));
        levelBtn->setParent(this);
        levelBtn->move(position[i][0],position[i][1]);

        connect(levelBtn,&GPushButton::clicked,[=]{
            qDebug()<<"gq chosen is"<<i+1;

            //实例化当前关卡
            pScene = new PlayScene(i+1);
            pScene->show();
            this->hide();

            //监听游戏场景中的返回信号
            connect(this->pScene,&PlayScene::ChooseSceneBack,[=]{
                this->show();//返回选关场景
                this->pScene->close();//隐藏游戏场景

                delete this->pScene;//删除动态变量
                this->pScene = NULL;//置空
            });
        });
    }
}

void SelectWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/gqbg1.jpg");//添加选关背景
    pix=pix.scaled(pix.width(),pix.height());
    painter.drawPixmap(0,0,pix.width(),pix.height(),pix);
}
